# Import packages
library(dplyr)
library(data.table)
library(ggplot2)
### Setting environment
## remove(list=ls())
# setwd("C:\\Users\\sunil\\Downloads\\College\\DAV\\Project")
# make evironment not to change large number to exponential
options(scipen = 999)
# Import dataset
nepal_dt <- read.csv("Source Dataset-API_NPL_DS2.csv", skip=4, header=TRUE, stringsAsFactors = FALSE)
meta_country <- read.csv("MetaData_Country.csv", header=TRUE, stringsAsFactors = FALSE)
meta_indictr <- read.csv("MetaData_Indicator.csv", header=TRUE, stringsAsFactors = FALSE)
nepal_dt
meta_country
meta_indictr
temp_df = filter(nepal_dt, grepl("tax", tolower(IndicatorName), fixed = TRUE) | grepl("tax", tolower(IndicatorCode), fixed = TRUE))
nepal_df <- temp_df
nepal_df
dim(nepal_df)
[1] 53 66
temp_df = filter(nepal_dt, grepl("gdp", tolower(IndicatorName), fixed = TRUE) | grepl("gdp", tolower(IndicatorCode), fixed = TRUE))
nepal_df <- rbind(nepal_df, temp_df)
nepal_df
dim(nepal_df)
[1] 143 66
temp_df = filter(nepal_dt, grepl("employment", tolower(IndicatorName), fixed = TRUE) | grepl("employment", tolower(IndicatorCode), fixed = TRUE))
nepal_df <- rbind(nepal_df, temp_df)
nepal_df
# Drop first and second column
nepal_df <- nepal_df[-c(1,2)]
nepal_df
# unique(nepal_df$IndicatorName)
#table(tolower(nepal_df$IndicatorName))
# Transposing the dataframe
# t(nepal_df)
df_t <- transpose(nepal_df)
rownames(df_t) <- colnames(nepal_df)
colnames(df_t) <- rownames(nepal_df)
# Rename the columns with the first row. Columns are not properly renamed from above lines.
colnames(df_t) <- df_t[2,]
# Remove the first and second row.
df_t <- df_t[-1:-2,]
nepal_df <- df_t
nepal_df
dim(nepal_df)[2]
[1] 242
# Converting columns to numeric types
#nepal_df$TM.TAX.MRCH.WM.AR.ZS = as.numeric(as.character(nepal_df$TM.TAX.MRCH.WM.AR.ZS))
#nepal_df$NY.GDP.PETR.RT.ZS = as.numeric(as.character(nepal_df$NY.GDP.PETR.RT.ZS))
nepal_df[1:dim(nepal_df)[2]] <- sapply(nepal_df[1:dim(nepal_df)[2]],as.numeric)
sapply(nepal_df, class)
TM.TAX.MRCH.WM.AR.ZS TM.TAX.MRCH.IP.ZS NY.TAX.NIND.KN TM.TAX.TCOM.BC.ZS TM.TAX.MANF.BC.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
GC.TAX.INTT.RV.ZS TM.TAX.MRCH.WM.FN.ZS TM.TAX.MRCH.SM.AR.ZS TM.TAX.TCOM.IP.ZS TM.TAX.MANF.IP.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
IC.TAX.GIFT.ZS GC.TAX.TOTL.GD.ZS GC.TAX.GSRV.VA.ZS IC.TAX.LABR.CP.ZS GC.TAX.YPKG.CN
"numeric" "numeric" "numeric" "numeric" "numeric"
TM.TAX.MRCH.BR.ZS NY.TAX.NIND.CN TM.TAX.MRCH.SR.ZS IC.TAX.OTHR.CP.ZS GC.TAX.YPKG.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
GC.TAX.IMPT.ZS GC.TAX.OTHR.CN GC.TAX.IMPT.CN TM.TAX.TCOM.WM.AR.ZS TM.TAX.MANF.WM.AR.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
IC.TAX.PAYM GC.TAX.EXPT.CN IC.TAX.TOTL.CP.ZS IC.FRM.INFM.ZS GC.TAX.GSRV.CN
"numeric" "numeric" "numeric" "numeric" "numeric"
GC.TAX.INTT.CN TM.TAX.TCOM.WM.FN.ZS TM.TAX.MANF.WM.FN.ZS TM.TAX.MRCH.SM.FN.ZS TM.TAX.TCOM.SM.AR.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
TM.TAX.MANF.SM.AR.ZS IC.FRM.METG.ZS GC.TAX.GSRV.RV.ZS TM.TAX.MRCH.BC.ZS NY.TAX.NIND.CD
"numeric" "numeric" "numeric" "numeric" "numeric"
TM.TAX.TCOM.SM.FN.ZS TM.TAX.MANF.SM.FN.ZS IC.TAX.METG GC.TAX.YPKG.RV.ZS IC.TAX.DURS
"numeric" "numeric" "numeric" "numeric" "numeric"
GC.TAX.TOTL.CN TM.TAX.TCOM.BR.ZS TM.TAX.MANF.BR.ZS TM.TAX.TCOM.SR.ZS TM.TAX.MANF.SR.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
IC.TAX.PRFT.CP.ZS GC.TAX.EXPT.ZS GC.TAX.OTHR.RV.ZS TG.VAL.TOTL.GD.ZS NY.GDP.MKTP.KD
"numeric" "numeric" "numeric" "numeric" "numeric"
NY.GDP.COAL.RT.ZS NY.GDP.PCAP.PP.KD NY.GDP.MINR.RT.ZS NY.GDP.MKTP.KN NY.GDP.DEFL.KD.ZG.AD
"numeric" "numeric" "numeric" "numeric" "numeric"
NV.SRV.TOTL.ZS ER.GDP.FWTL.M3.KD BX.TRF.PWKR.DT.GD.ZS SL.GDP.PCAP.EM.KD SE.XPD.TERT.PC.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
NY.GDS.TOTL.ZS NY.GDP.MKTP.KD.ZG NY.GDP.DEFL.KD.ZG SH.XPD.CHEX.GD.ZS SE.XPD.PRIM.PC.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
NY.GDP.PETR.RT.ZS NY.GDP.MKTP.CD NE.DAB.TOTL.ZS SH.XPD.GHED.GD.ZS SE.XPD.TOTL.GD.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
PA.NUS.PPPC.RF NY.GDP.MKTP.PP.KD NY.GDP.DEFL.ZS.AD NE.GDI.TOTL.ZS GC.TAX.TOTL.GD.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
FS.AST.DOMS.GD.ZS FM.AST.PRVT.GD.ZS EN.ATM.CO2E.KD.GD NY.GDP.PCAP.PP.CD NY.GDP.FRST.RT.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
NE.GDI.FTOT.ZS SE.XPD.SECO.PC.ZS NY.GDP.MKTP.CN.AD NV.IND.MANF.ZS NE.TRD.GNFS.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
GC.REV.XGRT.GD.ZS GB.XPD.RSDV.GD.ZS EG.USE.COMM.GD.PP.KD GC.NLD.TOTL.GD.ZS BN.CAB.XOKA.GD.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
BG.GSR.NFSV.GD.ZS NE.CON.PRVT.ZS GC.LBL.TOTL.GD.ZS FS.AST.PRVT.GD.ZS BM.KLT.DINV.WD.GD.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
NY.GDP.PCAP.KD NY.GDP.FCST.CN FS.AST.CGOV.GD.ZS EN.ATM.CO2E.PP.GD EG.GDP.PUSE.KO.PP.KD
"numeric" "numeric" "numeric" "numeric" "numeric"
EG.EGY.PRIM.PP.KD GC.NFN.TOTL.GD.ZS FM.LBL.BMNY.GD.ZS NY.GDP.PCAP.KD.ZG NY.GDP.FCST.KD
"numeric" "numeric" "numeric" "numeric" "numeric"
NY.GDP.TOTL.RT.ZS NY.GDP.MKTP.CN NE.RSB.GNFS.ZS MS.MIL.XPND.GD.ZS NY.GDP.NGAS.RT.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
NY.GDP.DISC.CN NV.IND.TOTL.ZS NE.GDI.FPRV.ZS GC.DOD.TOTL.GD.ZS FS.AST.DOMO.GD.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
EN.ATM.CO2E.PP.GD.KD BX.KLT.DINV.WD.GD.ZS NY.GDP.PCAP.KN NY.GDP.FCST.KN NE.IMP.GNFS.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
NY.GNS.ICTR.ZS NY.GDP.PCAP.CD NY.GDP.DISC.KN NV.AGR.TOTL.ZS CM.MKT.TRAD.GD.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
CM.MKT.LCAP.GD.ZS PA.NUS.PPP NY.GDP.MKTP.PP.CD NY.GDP.DEFL.ZS NE.EXP.GNFS.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
NY.GDP.PCAP.CN NY.GDP.FCST.CD NE.CON.TOTL.ZS GC.AST.TOTL.GD.ZS EG.GDP.PUSE.KO.PP
"numeric" "numeric" "numeric" "numeric" "numeric"
NE.CON.GOVT.ZS GC.XPN.TOTL.GD.ZS FD.AST.PRVT.GD.ZS SL.UEM.NEET.ZS SL.UEM.1524.FE.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.SRV.EMPL.ZS SL.FAM.WORK.ZS SL.EMP.TOTL.SP.FE.ZS SL.AGR.EMPL.MA.ZS per_lm_alllm.cov_q5_tot
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.UEM.INTM.MA.ZS SL.TLF.PART.ZS SL.TLF.0714.WK.MA.ZS SL.SRV.0714.MA.ZS SL.FAM.0714.MA.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.EMP.SELF.MA.ZS SL.AGR.0714.FE.ZS per_lm_alllm.cov_q1_tot SL.UEM.TOTL.FE.ZS SL.UEM.1524.MA.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.TLF.0714.MA.ZS SL.IND.EMPL.FE.ZS SL.EMP.TOTL.SP.MA.ZS SL.EMP.1524.SP.FE.NE.ZS SL.UEM.TOTL.FE.NE.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.UEM.1524.MA.NE.ZS SL.TLF.0714.FE.ZS SL.EMP.TOTL.SP.MA.NE.ZS SL.AGR.EMPL.ZS SL.UEM.INTM.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.SRV.0714.ZS SL.FAM.0714.ZS SL.EMP.SELF.ZS SL.AGR.0714.MA.ZS per_lm_alllm.cov_q2_tot
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.UEM.TOTL.MA.ZS SL.UEM.1524.ZS SL.TLF.0714.SW.FE.ZS SL.IND.EMPL.ZS SL.EMP.TOTL.SP.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.EMP.1524.SP.MA.NE.ZS SL.UEM.INTM.FE.ZS SL.TLF.PART.MA.ZS SL.SRV.0714.FE.ZS SL.FAM.0714.FE.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.EMP.SELF.FE.ZS per_lm_alllm.cov_pop_tot SL.UEM.NEET.MA.ZS SL.UEM.1524.FE.NE.ZS SL.TLF.0714.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.SRV.EMPL.MA.ZS SL.FAM.WORK.MA.ZS SL.EMP.TOTL.SP.FE.NE.ZS SL.AGR.EMPL.FE.ZS per_lm_alllm.cov_q4_tot
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.WAG.0714.MA.ZS SL.UEM.BASC.FE.ZS SL.TLF.0714.SW.ZS SL.SLF.0714.FE.ZS SL.EMP.WORK.FE.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.EMP.MPYR.FE.ZS SL.WAG.0714.ZS SL.UEM.BASC.MA.ZS SL.SLF.0714.MA.ZS SL.EMP.WORK.MA.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.EMP.MPYR.MA.ZS per_lm_alllm.adq_pop_tot SL.UEM.NEET.FE.ZS SL.TLF.0714.WK.ZS SL.SRV.EMPL.FE.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.FAM.WORK.FE.ZS SL.EMP.SMGT.FE.ZS SL.AGR.0714.ZS per_lm_alllm.cov_q3_tot SL.UEM.TOTL.NE.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.UEM.ADVN.FE.ZS SL.MNF.0714.FE.ZS SL.EMP.VULN.FE.ZS SL.EMP.1524.SP.MA.ZS SL.UEM.BASC.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.TLF.PART.FE.ZS SL.TLF.0714.WK.FE.ZS SL.SLF.0714.ZS SL.EMP.WORK.ZS SL.EMP.MPYR.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
per_lm_alllm.ben_q1_tot SL.UEM.TOTL.ZS SL.UEM.ADVN.MA.ZS SL.TLF.0714.SW.MA.ZS SL.MNF.0714.MA.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.EMP.VULN.MA.ZS SL.EMP.1524.SP.NE.ZS SL.UEM.TOTL.MA.NE.ZS SL.UEM.1524.NE.ZS SL.IND.EMPL.MA.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.EMP.TOTL.SP.NE.ZS SL.EMP.1524.SP.FE.ZS SL.WAG.0714.FE.ZS SL.UEM.ADVN.ZS SL.MNF.0714.ZS
"numeric" "numeric" "numeric" "numeric" "numeric"
SL.EMP.VULN.ZS SL.EMP.1524.SP.ZS
"numeric" "numeric"
# Replace NA values with 0
#nepal_df["TM.TAX.MRCH.WM.AR.ZS"][is.na(nepal_df["TM.TAX.MRCH.WM.AR.ZS"])] <- 0
#nepal_df["NY.GDP.PETR.RT.ZS"][is.na(nepal_df["NY.GDP.PETR.RT.ZS"])] <- 0
# Replace na values with 0 using is.na()
nepal_df[is.na(nepal_df)] <- 0
# Finding correlation between each columns in the dataframe
#cor(nepal_df$TM.TAX.MRCH.WM.AR.ZS, nepal_df$NY.GDP.PETR.RT.ZS)
View(cor(nepal_df))
Warning in View :
the standard deviation is zero
View(nepal_df)
#plot(nepal_df)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.